package cheese

import "FlyFight/Internal/bag"

func CreateCheese(cid uint8,x,y int,t ChType) (f *FlyCh,err error){
	f=new(FlyCh)
	f.Type=t
	f.CID=cid
	f.Blood=getBaseBlood(t)
	f.Pos=Point{x,y}
	f.Attack=getBaseAttack(t)
	f.Bag,err=bag.BuildBag(20)
	return f,err
}

func(c *FlyCh) DeleteCheese() error{
	if c.Bag!=nil{
		if err:=c.Bag.DeleteBag();err!=nil{
			return err
		}
	}
	return nil
}

// 获取奶酪的ID
func (c *FlyCh) GetCID() uint8 {
	return c.CID
}

// 获取奶酪类型
func (c *FlyCh) GetType() ChType {
	return c.Type
}

// 获取血量
func (c *FlyCh) GetBlood() int {
	return c.Blood
}

// 设置血量
func (c *FlyCh) SetBlood(blood int) {
	c.Blood = blood
}

// 获取攻击力
func (c *FlyCh) GetAttack() int {
	return c.Attack
}

// 设置攻击力
func (c *FlyCh) SetAttack(attack int) {
	c.Attack = attack
}

// 获取位置
func (c *FlyCh) GetPosition() Point {
	return c.Pos
}

// 设置位置
func (c *FlyCh) SetPosition(x, y int) {
	c.Pos = Point{x, y}
}

// 移动到新位置
func (c *FlyCh) Move(x, y int) {
	c.Pos.X = x
	c.Pos.Y = y
}

// 获取背包
func (c *FlyCh) GetBag() *bag.Bag {
	return c.Bag
}

// 受到伤害
func (c *FlyCh) TakeDamage(damage int) int {
	c.Blood -= damage
	if c.Blood < 0 {
		c.Blood = 0
	}
	return c.Blood
}

// 恢复血量
func (c *FlyCh) Heal(heal int) int {
	baseBlood := getBaseBlood(c.Type)
	c.Blood += heal
	if c.Blood > baseBlood {
		c.Blood = baseBlood
	}
	return c.Blood
}

// 是否存活
func (c *FlyCh) IsAlive() bool {
	return c.Blood > 0
}